package org.manusoft.refill.view;

import java.io.Serializable;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;

import org.manusoft.refill.domain.TDriverDetailsRf;
import org.manusoft.refill.dto.DriverDO;
import org.manusoft.refill.service.DriverService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

@Component("createDriver")
@Scope("request")
public class CreateDriver implements Serializable{
 
	private DriverDO  driver = new DriverDO();
	@Autowired
	private DriverService driverService;
	
	public CreateDriver() {}
	
	
	
	public DriverDO getDriver() {
		return driver;
	}

	public void setDriver(DriverDO driver) {
		this.driver = driver;
	}

	public void save(ActionEvent actionEvent) {
		TDriverDetailsRf driverDetailsRf = new TDriverDetailsRf();
		driverDetailsRf.setDriverName(driver.getDriverName());
		driverDetailsRf.setDriverAddress(driver.getDriverAddress());
		driverDetailsRf.setDriverDlNo(driver.getDriverDlNo());
		driverDetailsRf.setDriverDlExpDate(new java.sql.Date(driver.getDriverDlExpDate().getTime()));
		driverDetailsRf.setIsBlacklisted(driver.getIsBlacklisted());
		driverDetailsRf.setDriverMobileNo(driver.getDriverMobileNo());
		driverService.createUpdateDriver(driverDetailsRf);
		FacesMessage facesMessage = new FacesMessage(FacesMessage.SEVERITY_INFO, "Info", "Driver Data is saved");
		FacesContext.getCurrentInstance().addMessage(null, facesMessage);
//		driver = new TDriverDetailsRf();
	}
}